//
//  youtubeDetailViewController.m
//  IntroductionApp
//
//  Created by 英司 菅澤 on 12/02/13.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "youtubeDetailViewController.h"

@implementation youtubeDetailViewController

@synthesize thumbView = _thumbView;
@synthesize titleLabel = _titleLabel;
@synthesize commentLabel = _commentLabel;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    _thumbView = nil;
    _titleLabel = nil;
    _commentLabel = nil;
}

-(void)dealloc{
    [ _thumbView release ];
    [ _titleLabel release ];
    [ _commentLabel release ];
    
    [ super dealloc ];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

/* ====================================================================================== */
#pragma mark - setView
/* ====================================================================================== */

-(void)setMovieData:(NSDictionary*)movieDic{
        
    NSString *htmlSrc = @"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 250\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"250\" height=\"190\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"250\" height=\"190\"></embed></object></div></body></html>";
    
    NSString *thumbURL = [ NSString stringWithFormat:htmlSrc,[ movieDic objectForKey:@"link" ],[ movieDic objectForKey:@"link" ]];
    NSLog(@"thumbURL = %@",thumbURL);
    
    [self.thumbView loadHTMLString:thumbURL baseURL:[NSURL URLWithString:nil]];
    
    // Labelのサイズ調整
    NSString *titleStr   = [ movieDic objectForKey:@"title" ];
    NSString *commentStr = [ movieDic objectForKey:@"comment" ];
    
    CGSize textBounds = CGSizeMake(270, 9999);
    
    CGSize titleSize = [titleStr sizeWithFont:[UIFont boldSystemFontOfSize:19 ] 
                         constrainedToSize:textBounds 
                             lineBreakMode:UILineBreakModeCharacterWrap];
    
	CGSize mainSize = [commentStr sizeWithFont:[UIFont systemFontOfSize:17] 
                       constrainedToSize:textBounds 
						   lineBreakMode:UILineBreakModeCharacterWrap];
    
	CGFloat height = self.titleLabel.frame.origin.y + titleSize.height;
    
    self.titleLabel.frame   = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y, 270, titleSize.height);
    self.commentLabel.frame = CGRectMake(self.commentLabel.frame.origin.x, height , 270, mainSize.height);
    
    // title
    self.titleLabel.text = titleStr;
    // comment
    self.commentLabel.text = commentStr;
    
}


@end
